﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace GFE.SharePoint.CSharpExtensions
{
    public static class IEnumerableTExtensions
    {
        /// <summary>
        /// Generic ForEach to be used with lamda. 
        /// eg:
        ///   callInput.Parameters.Values   
        ///         .ForEach<CallInput.MethodParameter> 
        ///         (a =>
        ///         {
        ///             a.ParameterDetails = methodInfo.Parameters.Where(b => b.Name == a.Name).First();
        ///         });
        /// </summary>
        /// <typeparam name="T">Type of element to be enumerated</typeparam>
        /// <param name="enumeration">List of elements to be enumerated</param>
        /// <param name="action">Action to be performed for each element in list</param>
        public static void ForEach<T>(this IEnumerable<T> enumeration, Action<T> action)
        {
            foreach (var item in enumeration) { action(item); }
        }
    }
}
